package org.example.service;

import jakarta.annotation.Resource;
import jakarta.transaction.Transactional;
import org.example.dao.IDeliveryAddressRepository;
import org.example.entity.DeliveryAddress;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeliveryAdressService {
    @Resource
    private IDeliveryAddressRepository deliveryAddressRepository;
    public DeliveryAddress findByDaId(Integer daId){
        return deliveryAddressRepository.findByDaId(daId);
    }

    public List<DeliveryAddress> findAllByUserId(String userId){
        return deliveryAddressRepository.findAllByUserId(userId);
    }
    public DeliveryAddress addDeliveryAdress(DeliveryAddress d){
        return deliveryAddressRepository.save(d);
    }
    public void deleteByDaId(Integer daId){
        deliveryAddressRepository.deleteByDaId(daId);
    }
    @Transactional
    public void updateByDaIdFromEntity(Integer daId, String address, String contactTel, Integer contactSex, String contactName){
        deliveryAddressRepository.updateByDaIdFromEntity(daId,address,contactTel,contactSex,contactName);

    }
}
